package two_xia.ex8.Demo04;

import java.util.ArrayList;

public class DeviceFactory {
    private ArrayList devices = new ArrayList();
    private int totalTerminal = 0;

    public DeviceFactory() {
        NetworkDevice nd1 = new Switch("交换机");
        devices.add(nd1);
        NetworkDevice nd2 = new Hub("集线器");
        devices.add(nd2);
    }

    public NetworkDevice getNetworkDevice(String type) {
        if (type.equalsIgnoreCase("cisco")) {
            totalTerminal++;
            return (NetworkDevice) devices.get(0);
        } else if (type.equalsIgnoreCase("tp")) {
            totalTerminal++;
            return (NetworkDevice) devices.get(1);
        } else {
            return null;
        }
    }

    public int getTotalDevice() {
        return devices.size();
    }

    public int getTotalTerminal() {
        return totalTerminal;
    }
}